//
//  AccountCenterButtonPriceBar.m
//  JiaoX
//
//  Created by jiaoxiu－005 on 15/1/19.
//  Copyright (c) 2015年 北京娇羞科技有限公司. All rights reserved.
//

#import "AccountCenterButtonPriceBar.h"
#define margin 10
#define marginTop 8
#define ACCOUNT_CENTER_PRICEBAR_TEXT [DimensUtils getScaleX:14]
#define ACCOUNT_CENTER_PRACTCIAL_TEXT [DimensUtils getScaleX:12]
#define ACCOUNT_CENTER_PRICEBAR_TEXT2 [DimensUtils getScaleX:11]
@interface AccountCenterButtonPriceBar()
{
    UILabel *_countDefaultLabel;
    UILabel *_practicalPriceLabel;
    UILabel *_countPriceLabel;
    UILabel *_countSpareLabel;
    UIButton *_toAccountButton;
}
@end
@implementation AccountCenterButtonPriceBar


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setBackgroundColor:[UIColor whiteColor]];
        UIView * lineView  = [[UIView alloc]initWithFrame:CGRectMake(0, 0, JXScreenW, 0.5)];
        [lineView setBackgroundColor:JXColor(204, 204, 204)];
        [self addSubview:lineView];
        
        //1.默认的总计文字
        NSString *defaultText = @"总计 :";
        _countDefaultLabel = [[UILabel alloc]init];
        [_countDefaultLabel setTextColor:JXColor(0, 0, 0)];
        [_countDefaultLabel setText:defaultText];
        [_countDefaultLabel setFont:[UIFont systemFontOfSize:ACCOUNT_CENTER_PRICEBAR_TEXT]];
        CGSize defaultTextSize = [defaultText sizeWithFont:[UIFont systemFontOfSize:ACCOUNT_CENTER_PRICEBAR_TEXT]];
        [_countDefaultLabel setFrame:CGRectMake(margin, marginTop, defaultTextSize.width, defaultTextSize.height)];
        [self addSubview:_countDefaultLabel];
        
        //实际支付的价格
        _practicalPriceLabel = [[UILabel alloc]init];
        [_practicalPriceLabel setTextColor:JXThemeColor];
        [_practicalPriceLabel setFont:[UIFont systemFontOfSize:ACCOUNT_CENTER_PRACTCIAL_TEXT]];
        [_practicalPriceLabel setFrame:CGRectMake(CGRectGetMaxX(_countDefaultLabel.frame)+JXPublicInset, marginTop, defaultTextSize.width, defaultTextSize.height)];
        [self addSubview:_practicalPriceLabel];
        
        
        //2.当前总价
        NSString *defaultPriceText = @"0";
        _countPriceLabel = [[UILabel alloc]init];
        [_countPriceLabel setTextColor:JXColor(248, 51, 143)];
        [_countPriceLabel setText:defaultPriceText];
        [_countPriceLabel setFont:[UIFont systemFontOfSize:ACCOUNT_CENTER_PRICEBAR_TEXT]];
        CGSize defaultPriceSize = [defaultPriceText sizeWithFont:[UIFont systemFontOfSize:ACCOUNT_CENTER_PRICEBAR_TEXT]];
        [_countPriceLabel setFrame:CGRectMake(CGRectGetMaxX(_countDefaultLabel.frame) + margin,marginTop, defaultPriceSize.width, defaultPriceSize.height)];
        [self addSubview:_countPriceLabel];
        //3.节省的价格
        NSString *defaultSpareText = @"为您节省了￥0";
        _countSpareLabel = [[UILabel alloc]init];
        [_countSpareLabel setTextColor:JXColor(102, 102, 102)];
        [_countSpareLabel setText:defaultSpareText];
        [_countSpareLabel setFont:[UIFont systemFontOfSize:ACCOUNT_CENTER_PRICEBAR_TEXT2]];
        CGSize defaultSpareSize = [defaultSpareText sizeWithFont:[UIFont systemFontOfSize:ACCOUNT_CENTER_PRICEBAR_TEXT2]];
        [_countSpareLabel setFrame:CGRectMake(margin, CGRectGetMaxY(_countDefaultLabel.frame), defaultSpareSize.width, defaultSpareSize.height)];
        [self addSubview:_countSpareLabel];
        
        //4.去结算按钮
        _toAccountButton =[[UIButton alloc]init];
        [_toAccountButton setTitle:@"提交订单" forState:UIControlStateNormal];
        [_toAccountButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_toAccountButton setContentMode:UIViewContentModeCenter];
        [_toAccountButton setBackgroundImage:[UIImage resizedImage:@"btn_login_bg"] forState:UIControlStateNormal];
        [_toAccountButton addTarget:self action:@selector(toOrderStatusPage) forControlEvents:UIControlEventTouchUpInside];
        [_toAccountButton setFrame:CGRectMake(JXScreenW-97-10,marginTop, 97.5, 32.5)];
        [self addSubview:_toAccountButton];
        [self setBounds:CGRectMake(0, 0, JXScreenW, 52.5)];
        
    }
    return self;
}
-(void)setPriceNum:(double)priceNum{
    NSString *price = [NSString stringWithFormat:@"¥%.1f",priceNum];
    CGSize priceSize = [price sizeWithFont:[UIFont systemFontOfSize:ACCOUNT_CENTER_PRICEBAR_TEXT]];
    [_countPriceLabel setSize:priceSize];
    [_countPriceLabel setText:price];
}
-(void)setSpareNum:(double)spareNum{
    NSString *spare = [NSString stringWithFormat:@"为您节省了¥%.1f",spareNum];
    CGSize spareSize = [spare sizeWithFont:[UIFont systemFontOfSize:ACCOUNT_CENTER_PRICEBAR_TEXT2]];
    [_countSpareLabel setSize:spareSize];
    [_countSpareLabel setText:spare];
}

-(void)setPracticalPrice:(double)practicalPrice{
    NSString *practical = [NSString stringWithFormat:@"(实付:¥%.1f)",practicalPrice];
    CGSize practicalSize = [practical sizeWithFont:[UIFont systemFontOfSize:ACCOUNT_CENTER_PRACTCIAL_TEXT]];
    _practicalPriceLabel.x =CGRectGetMaxX(_countPriceLabel.frame)+JXPublicInset;
    [_practicalPriceLabel setSize:practicalSize];
    [_practicalPriceLabel setText:practical];
}

//去结算
-(void)toOrderStatusPage
{
    if ([self.delegate respondsToSelector:@selector(toOrderStatusPage)]) {
        [_delegate toOrderStatusPage];
    }
}
-(void)setBtnText:(NSString *)btnText{
    [_toAccountButton setTitle:btnText forState:UIControlStateNormal];
}


@end
